// Video processing related types

export interface VideoFile {
  id: string;
  name: string;
  originalName: string;
  path: string;
  size: number;
  duration: number;
  format: string;
  codec: string;
  resolution: Resolution;
  bitrate: number;
  frameRate: number;
  aspectRatio: string;
  audioTracks: AudioTrack[];
  subtitles: SubtitleTrack[];
  metadata: VideoMetadata;
  thumbnail?: string;
  createdAt: Date;
  updatedAt: Date;
}

export interface Resolution {
  width: number;
  height: number;
}

export interface AudioTrack {
  index: number;
  codec: string;
  bitrate: number;
  sampleRate: number;
  channels: number;
  language?: string;
  title?: string;
}

export interface SubtitleTrack {
  index: number;
  codec: string;
  language?: string;
  title?: string;
  forced?: boolean;
  default?: boolean;
}

export interface VideoMetadata {
  title?: string;
  description?: string;
  tags: string[];
  genre?: string;
  year?: number;
  director?: string;
  cast?: string[];
  rating?: string;
  [key: string]: any;
}

export interface ProcessTask {
  id: string;
  type: TaskType;
  status: TaskStatus;
  progress: TaskProgress;
  inputFiles: VideoFile[];
  outputPath: string;
  options: ProcessOptions;
  result?: ProcessResult;
  error?: TaskError;
  createdAt: Date;
  startedAt?: Date;
  completedAt?: Date;
  estimatedDuration?: number;
}

export type TaskType =
  | 'convert'
  | 'compress'
  | 'resize'
  | 'extract_audio'
  | 'extract_frames'
  | 'merge'
  | 'split'
  | 'rotate'
  | 'crop'
  | 'add_watermark'
  | 'stabilize'
  | 'denoise'
  | 'batch_process';

export type TaskStatus =
  | 'pending'
  | 'queued'
  | 'processing'
  | 'completed'
  | 'failed'
  | 'canceled'
  | 'paused';

export interface TaskProgress {
  percentage: number;
  currentFrame: number;
  totalFrames: number;
  fps: number;
  timeElapsed: number;
  timeRemaining: number;
  currentPhase: string;
}

export interface TaskError {
  code: string;
  message: string;
  details?: string;
  timestamp: Date;
}

export interface ProcessOptions {
  outputFormat?: string;
  quality?: QualityPreset | number;
  resolution?: Resolution;
  bitrate?: number;
  frameRate?: number;
  audioCodec?: string;
  videoCodec?: string;
  cropArea?: CropArea;
  rotateAngle?: number;
  watermark?: WatermarkOptions;
  filters?: VideoFilter[];
  startTime?: number;
  endTime?: number;
  overwrite?: boolean;
}

export type QualityPreset = 'low' | 'medium' | 'high' | 'lossless';

export interface CropArea {
  x: number;
  y: number;
  width: number;
  height: number;
}

export interface WatermarkOptions {
  text?: string;
  image?: string;
  position: WatermarkPosition;
  opacity: number;
  fontSize?: number;
  color?: string;
}

export type WatermarkPosition =
  | 'top-left'
  | 'top-right'
  | 'bottom-left'
  | 'bottom-right'
  | 'center';

export interface VideoFilter {
  name: string;
  parameters: Record<string, any>;
}

export interface ProcessResult {
  success: boolean;
  outputFiles: string[];
  originalSize: number;
  newSize: number;
  compressionRatio: number;
  processingTime: number;
  qualityScore?: number;
}

export interface BatchProcessConfig {
  operation: TaskType;
  options: ProcessOptions;
  outputPath: string;
  fileNaming: FileNamingPattern;
  maxConcurrency: number;
  skipErrors: boolean;
  overwriteExisting: boolean;
}

export interface FileNamingPattern {
  prefix?: string;
  suffix?: string;
  includeOriginalName: boolean;
  includeTimestamp: boolean;
  includeCounter: boolean;
  customPattern?: string;
}

export interface VideoStats {
  totalVideosProcessed: number;
  totalProcessingTime: number;
  totalSpaceSaved: number;
  averageCompressionRatio: number;
  mostUsedFormat: string;
  processingHistory: ProcessingHistoryItem[];
}

export interface ProcessingHistoryItem {
  date: Date;
  taskType: TaskType;
  inputSize: number;
  outputSize: number;
  duration: number;
  success: boolean;
}

export interface VideoFormat {
  extension: string;
  name: string;
  mimeType: string;
  supportedCodecs: string[];
  maxResolution?: Resolution;
  supportsAudio: boolean;
  supportsSubtitles: boolean;
}

export interface VideoPreset {
  id: string;
  name: string;
  description: string;
  taskType: TaskType;
  options: ProcessOptions;
  isBuiltIn: boolean;
  category: PresetCategory;
}

export type PresetCategory = 'web' | 'mobile' | 'social' | 'broadcast' | 'archive' | 'custom';

// Timeline Editor Types
export interface Timeline {
  id: string;
  tracks: Track[];
  duration: number;
  fps: number;
  resolution: Resolution;
}

export interface Track {
  id: string;
  type: TrackType;
  name: string;
  clips: Clip[];
  muted: boolean;
  locked: boolean;
  visible: boolean;
  height: number;
}

export type TrackType = 'video' | 'audio' | 'subtitle';

export interface Clip {
  id: string;
  trackId: string;
  sourceFile: VideoFile;
  startTime: number;
  endTime: number;
  trackStartTime: number;
  duration: number;
  trimStart: number;
  trimEnd: number;
  effects: Effect[];
  transitions: Transition[];
  volume: number;
  muted: boolean;
}

export interface Effect {
  id: string;
  type: EffectType;
  name: string;
  parameters: Record<string, any>;
  startTime: number;
  duration: number;
  enabled: boolean;
}

export type EffectType =
  | 'color_correction'
  | 'brightness'
  | 'contrast'
  | 'saturation'
  | 'blur'
  | 'sharpen'
  | 'noise_reduction'
  | 'stabilization'
  | 'speed'
  | 'reverse';

export interface Transition {
  id: string;
  type: TransitionType;
  duration: number;
  position: 'start' | 'end';
  parameters: Record<string, any>;
}

export type TransitionType = 'fade_in' | 'fade_out' | 'cross_fade' | 'slide' | 'wipe' | 'dissolve';
